package com.tengju.user.infrastructure.repository.convert;

import com.tengju.user.domain.model.chief.ChiefGenSecRelation;
import com.tengju.user.domain.model.chief.ChiefId;
import com.tengju.user.domain.model.chief.ChiefSecRelationType;
import com.tengju.user.domain.model.department.DepartmentId;
import com.tengju.user.domain.model.user.UserIdCode;
import com.tengju.user.infrastructure.persistence.mybatis.dataobject.ChiefGenSecRelationDO;

import java.util.Optional;

/**
 * @Author: 李大仙
 * @Date: 2021/5/6 3:12 下午
 */
public class ChiefGenSecRelationConvert {

    public static ChiefGenSecRelation convert(ChiefGenSecRelationDO chiefGenSecRelationDO) {
        if (chiefGenSecRelationDO == null) {
            return null;
        }
        return new ChiefGenSecRelation(
                new ChiefId(chiefGenSecRelationDO.getChiefId()),
                chiefGenSecRelationDO.getChiefName(),
                chiefGenSecRelationDO.getChiefNickname(),
                new UserIdCode(chiefGenSecRelationDO.getGenSecIdCode()),
                ChiefSecRelationType.fromVal(chiefGenSecRelationDO.getRelationType()),
                chiefGenSecRelationDO.getDepartmentId() <= 0 ? null : new DepartmentId(chiefGenSecRelationDO.getDepartmentId()),
                chiefGenSecRelationDO.getDepartmentName(),
                chiefGenSecRelationDO.getDepartmentLeaderId() <= 0 ? null : new ChiefId(chiefGenSecRelationDO.getDepartmentLeaderId()),
                chiefGenSecRelationDO.getDepartmentLeaderName(),
                chiefGenSecRelationDO.getCreateBy(),
                chiefGenSecRelationDO.getUpdateBy());
    }

    public static ChiefGenSecRelationDO convert(ChiefGenSecRelation chiefGenSecRelation) {
        if (chiefGenSecRelation == null) {
            return null;
        }
        ChiefGenSecRelationDO chiefGenSecRelationDO = new ChiefGenSecRelationDO();
        chiefGenSecRelationDO.setChiefId(chiefGenSecRelation.getChiefId().getValue());
        // 定时任务刷入总监的部门
        if (chiefGenSecRelation.getGenSecIdCode() != null ){
            chiefGenSecRelationDO.setGenSecIdCode(chiefGenSecRelation.getGenSecIdCode().getValue());
        }
        if (chiefGenSecRelation.getCreateBy() != null ){
            chiefGenSecRelationDO.setCreateBy(chiefGenSecRelation.getCreateBy());
        }
        if (chiefGenSecRelation.getUpdateBy() != null ){
            chiefGenSecRelationDO.setUpdateBy(chiefGenSecRelation.getUpdateBy());
        }
        chiefGenSecRelationDO.setChiefName(chiefGenSecRelation.getChiefName());
        chiefGenSecRelationDO.setChiefNickname(chiefGenSecRelation.getChiefNickname());
        chiefGenSecRelationDO.setDepartmentName(chiefGenSecRelation.getDepartmentName());
        chiefGenSecRelationDO.setDepartmentLeaderName(chiefGenSecRelation.getDepartmentLeaderName());
        if (chiefGenSecRelation.getChiefSecRelationType() != null){
            chiefGenSecRelationDO.setRelationType(chiefGenSecRelation.getChiefSecRelationType().getVal());
        }
        if (chiefGenSecRelation.getDepartmentId() != null){
            chiefGenSecRelationDO.setDepartmentId(chiefGenSecRelation.getDepartmentId().getValue());
        }
        if (chiefGenSecRelation.getDepartmentLeaderId() != null){
            chiefGenSecRelationDO.setDepartmentLeaderId(chiefGenSecRelation.getDepartmentLeaderId().getValue());
        }
        return chiefGenSecRelationDO;
    }

}
